package version2024.medium;

import java.util.Scanner;

/**
 * @author sunhl
 * @Description: HJ63 DNA序列  字符串, 正则表达式, 移动窗口
 * @Date: created in 2025/1/2 星期四 20:56
 * @Modified By:
 */
public class HJ63_DNASequence {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case

            String str = in.next();
            int n = in.nextInt();
            // 占比是百分比, 用小数
            double len = 0.0;
            // 保存GC占比高的子段
            String result = "";

            // 每次将长度为n的窗口向后移一位
            for (int i = 0; i < str.length() - n + 1; i++) {
                String aim = str.substring(i, i + n);
                // 正则很重要, 替换所有非C和G的字符
                String res = aim.replaceAll("[^CG]", "");
                double cur = (double) res.length() / (double) n;
                if (cur > len) {
                    len = cur;
                    result = aim;
                }
            }

            System.out.println(result);
        }
    }
}
